package com.dorm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dorm.entity.Room;
import com.dorm.mapper.RoomMapper;
import com.dorm.service.RoomService;
import org.springframework.stereotype.Service;

/**
 * 房间服务实现类
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements RoomService {

    @Override
    public Page<Room> pageQuery(Integer pageNum, Integer pageSize, Long buildingId, String roomNo) {
        Page<Room> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Room> wrapper = new LambdaQueryWrapper<>();
        
        if (buildingId != null) {
            wrapper.eq(Room::getBuildingId, buildingId);
        }
        if (roomNo != null && !roomNo.isEmpty()) {
            wrapper.like(Room::getRoomNo, roomNo);
        }
        
        wrapper.orderByAsc(Room::getBuildingId, Room::getFloor, Room::getRoomNo);
        return page(page, wrapper);
    }
}

